package com.atguigu.gmall;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

//异步编排    线程间通信
public class CompletableFutureDemo {
    public static void main(String[] args) {
        //自定义线程池
        ThreadPoolExecutor threadPoolExecutor = new
                ThreadPoolExecutor(
                        5,//核心线程
                10,//最大线程数
                3,//存活时间
                TimeUnit.SECONDS,//存活时间单位
                new ArrayBlockingQueue<>(10)//阻塞队列
        );
        //1:开启第一个线程
    /*    CompletableFuture.runAsync(() -> {
            //   ForkJoinPool.commonPool-worker-1
            System.out.println(Thread.currentThread().getName());
        });  */
        CompletableFuture.runAsync(()->{
            //  pool-1-thread-1
            System.out.println(Thread.currentThread().getName());
        },threadPoolExecutor);

        CompletableFuture.supplyAsync(()->{
            System.out.println(Thread.currentThread().getName());
            return 123;// 返回类型是U 任意类型的
        },threadPoolExecutor);
        //Runnable    |   Callable 接口


    }
}
